<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>选择分类商品</title>

    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>
    <style>
        .selectActive {
            background-color: #FADDCF !important;
            color: #EB7B3D;

        }
        .header{
            background-color: #9D0152;
            color: #ffffff;
          }
        .getback{
          position:absolute;
          left:10px;
          font-size:14px;
        }
    </style>
</head>
<body style="background-color:#F0F0F0">
<div id="app" style="padding-top:60px">
  <div id="blank" class="header shopheader" v-cloak>
      <div v-back.tapmode class="getback">取消</div>
      <span class="title">选择分类商品</span>
      <span v-back.tapmode   style="position:absolute;right:10px;font-size:14px;">保存(2)</span>
  </div>
  <div class="searchname">
  <input  style="height:100%;width:80%;outline:none;padding-left:20px" placeholder="请输入搜索关键词">
  </div>
  <div class="goods_info" v-for="(good, index) in goods">
    <div class="goods-detail" v-myclick="[good, selectStatus]">
      <div class="goods-pic">
        <img v-image-resize="{src:good.pic}" :key="good.goods_id">
      </div>
      <div class="goods-detail-right">
        <div class="goods-detail-title">{{good.title}}</div>
        <div class="sell-price">
          <span style="color:#666666">售价：</span><span style="color:#9d0152">￥{{good.price}}</span>
        </div>
        <div class="goods_number" @click.stop="selectStatus(good)">
          <span>库存：{{good.stock}}</span>
          <span>销量：{{good.sale_count}}</span>
          <img class="goods-radio" v-src="'../../image/unselected.png'" v-show="good.select !== 1">
          <img class="goods-confirm" v-src="'../../image/selected.png'" v-show="good.select == 1">
        </div>
      </div>
    </div>
  </div>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/url.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/components.js"></script>
<script>
var vm,
    goodsselected=[],
    goods;

apiready = function () {
  showProgress();
  UIScrollPicture = api.require('UIScrollPicture');
  MNActionButton = api.require('PIActionButton');
  wx = api.require('wx');
  setBSImg();
  var data = {
      member_id: getPrefs('member_id'),
  };
  var callback = function (ret) {
      var home = ret.content;
      goods = home.memberGoods;
      // console.log(JSON.stringify(goods));
      initApp();
      api.parseTapmode();
  };
  pinet.post(URL.getCategorygoodsInfo, data, callback);
};

function initApp() {
    vm = new Vue({
        el: "#app",
        data: {
            goods: goods,
            url: URL.getMemberShopInfo,
        },
        methods: {
            selectStatus: function (good) {
              if(good.select == 1){
                good.select = -1;
                goodsselected.remove(good.goods_id);
              }else{
                good.select = 1;
                goodsselected.push(good.goods_id);
              }
            },
            changeGoodsState:function(type){
              goodsselected = goodsselected.join(',');
              var data = {
                  member_id: getPrefs('member_id'),
                  goodsselected: goodsselected,
                  type:type,
                  state:goodsstate
              };
              var callback = function (ret) {
                if(ret.errcode==0){
                  var home = ret.content;
                  vm.goods = home.memberGoods;
                  vm.states = home.states;
                  goodsselected= [];
                }
              };
              pinet.post(URL.changeGoodsState, data, callback);
            }
        },
    });
}

function addListeners() {
    api.addEventListener({
        name: 'viewappear'
    }, function () {
        // onPageStart();
    });

    api.addEventListener({
        name: 'viewdisappear'
    }, function (ret, err) {
        // onPageEnd();
    });

    api.addEventListener({
        name: 'keyback'
    }, function (ret, err) {
        // onPageEnd();
        api.closeWin();
    });
}


</script>
</html>
